//项目路径
var strPath = window.document.location.pathname;
//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
var postPath = "/gdp";

var pid = 1;

var id = 0;
$(function(){
	$("#adf").hide();
	$("#codesysid").hide();
	// 左侧tree数据绑定
	var setting = {
		data : {
			key : {
				title : "hint"
			},
			simpleData : {
				enable : true
			}
		},
		callback : {
			onClick : onClick
		}
	};
	var zNodes = GetLeftTreeData();
	$.fn.zTree.init($("#tree"), setting, zNodes);

	// Tree点击事件
	function onClick(event, treeId, treeNode, clickFlag) {
		pid = treeNode.pid;
		id = treeNode.id;
	}
	
	$("#downloadjarss").click(function(){
		//alert(postPath+"WEB-INF\extjar\1510222807502\tomcat-api.jar");
		window.location.href=postPath+"/system/uploadfile/download";
//		$.ajax({
//			url : postPath + '/system/uploadfile/download',
//			type : 'get',
//			data : {
//				keys : id
//			},
//			success : function(data) {
//				bootbox.alert("删除成功!");
//				var zNodes = GetLeftTreeData();
//				$.fn.zTree.init($("#tree"), setting, zNodes);
//				$('#tree').bootstrapTable('refresh');
//			},
//			error : function() {
//				bootbox.alert("删除失败!");
//			}
//		});
	});
	
	$("#deletety").click(function(){
		if(pid!=0){
			bootbox.alert("请选择主体jar包");
			return;
		}
		bootbox.confirm("确认删除此Jar包?", function(result) {
			if (result == false)
				return;
			$.ajax({
				url : postPath + '/system/uploadfile/deleteJar',
				type : 'get',
				data : {
					keys : id
				},
				success : function(data) {
					bootbox.alert("删除成功!");
					var zNodes = GetLeftTreeData();
					$.fn.zTree.init($("#tree"), setting, zNodes);
					$('#tree').bootstrapTable('refresh');
				},
				error : function() {
					bootbox.alert("删除失败!");
				}
			});
		});
	});
});
//获取左侧列表数据
function GetLeftTreeData() {
	var treeData;
	$.ajax({
		type : 'get',
		url : postPath + '/system/uploadfile/getTreeList',
		async : false,
		success : function(res) {
			treeData = res;
		},
		error : function() {
			alert('error...');
		}
	});
	return treeData;
}
$('#file-0a').fileinput({
    language: 'zh', //设置语言
    uploadUrl: postPath + '/system/uploadfile/upload2', //上传的地址
    allowedFileExtensions: ['jar'],//接收的文件后缀
    autoReplace : true,
    maxFileCount : 1,
    browseClass : "btn btn-primary", //按钮样式 
    previewFileIcon : "<i class='glyphicon glyphicon-king'></i>",
    uploadAsync: true, //默认异步上传
    showUpload: true, //是否显示上传按钮
    showRemove : true, //显示移除按钮
    showPreview : true, //是否显示预览
    browseClass:"btn blue-steel",
});
$('#file-0a').on('filepreupload', function(event, data, previewId, index) {     //上传中
    var form = data.form, files = data.files, extra = data.extra,
    response = data.response, reader = data.reader;
    //console.log('文件正在上传');
    return ;
})
$('#file-0a').on("fileuploaded", function (event, data, previewId, index) {    //一个文件上传成功
    //console.log('文件上传成功！'+data.jqXHR.responseJSON.msg);
	// 左侧tree数据绑定
	var setting = {
		data : {
			key : {
				title : "hint"
			},
			simpleData : {
				enable : true
			}
		},
		callback : {
			onClick : onCli
		}
	};
	var zNodes = GetLeftTreeData();
	$.fn.zTree.init($("#tree"), setting, zNodes);
       
})
function onCli(event, treeId, treeNode, clickFlag) {
	pid = treeNode.pid;
	id = treeNode.id;
}
$('#file-0a').on('fileerror', function(event, data, msg) {  //一个文件上传失败
    //console.log('文件上传失败！'+data.id);
    bootbox.alert(data.jqXHR.responseJSON.msg);
})
